//
// Created by edward on 22-11-16.
//

#ifndef CONCURRENCE_ACTIVITY_H
#define CONCURRENCE_ACTIVITY_H

#include "utils.h"
#include <iostream>

namespace edward::multithread {

    //生产者线程
    template<typename Queue>
    void produce(Queue &messageQueue) {
        typename Queue::Type t;
        while (std::cin >> t) {
            messageQueue.push(std::move(t));
        }
    }

    //消费者线程
    template<typename Queue>
    void consume(Queue &messageQueue) {
        typename Queue::Type t;
        int idx = 0;
        while (true) {
            t = messageQueue.pop(); //数据的处理在临界区外
            edward::print("[", idx++, "]:", t);
        }
    }
}

#endif //CONCURRENCE_ACTIVITY_H
